{% set pypi_name = 'cyborg' %}
{% set source = fetch_source('https://tarballs.openstack.org/cyborg/cyborg-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}
%if 0%{?rhel} || 0%{?fedora}
%global rdo 1
%endif
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        OpenStack Accelerator as a Service
License:        {{ license('Apache-2.0') }}
URL:            https://docs.openstack.org/cyborg
Source0:        {{ source|basename }}
BuildRequires:  fdupes
BuildRequires:  openstack-macros
BuildRequires:  {{ py2pkg('tempest') }}
BuildRequires:  {{ py3('WSME') }}
BuildRequires:  {{ py3('ddt') }}
BuildRequires:  {{ py3('eventlet') }}
BuildRequires:  {{ py3('fixtures') }}
BuildRequires:  {{ py3('jsonpatch') }}
BuildRequires:  {{ py3('keystoneauth1') }}
BuildRequires:  {{ py3('keystonemiddleware') }}
BuildRequires:  {{ py3('mock') }}
BuildRequires:  {{ py3('oslo.config') }}
BuildRequires:  {{ py3('oslo.context') }}
BuildRequires:  {{ py3('oslo.db') }}
BuildRequires:  {{ py3('oslo.i18n') }}
BuildRequires:  {{ py3('oslo.log') }}
BuildRequires:  {{ py3('oslo.policy') }}
BuildRequires:  {{ py3('oslo.versionedobjects') }}
BuildRequires:  {{ py3('oslosphinx') }}
BuildRequires:  {{ py3('oslotest') }}
BuildRequires:  {{ py3('pecan') }}
BuildRequires:  {{ py3('psutil') }}
BuildRequires:  {{ py3('six') }}
Requires:       python3-{{ pypi_name }} = %{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
Requires(pre):  pwdutils
%{?systemd_requires}
%endif
%if 0%{?rdo}
BuildRequires:  systemd
Requires(post): systemd
Requires(postun): systemd
Requires(pre):  shadow-utils
Requires(preun): systemd
%endif

%description
Cyborg (previously known as Nomad) is an OpenStack project that aims to
provide a general purpose management framework for acceleration
resources (i.e. various types of accelerators such as GPU, FPGA, ASIC,
NP, SoCs, NVMe/NOF SSDs, ODP, DPDK/SPDK and so on).

%package -n     python3-{{ pypi_name }}
Summary:        Cyborg Python library
Group:          Applications/System
Requires:       {{ py3('SQLAlchemy') }}
Requires:       {{ py3('WSME') }}
Requires:       {{ py3('alembic') }}
Requires:       {{ py3('eventlet') }}
Requires:       {{ py3('jsonpatch') }}
Requires:       {{ py3('keystoneauth1') }}
Requires:       {{ py3('keystonemiddleware') }}
Requires:       {{ py3('oslo.concurrency') }}
Requires:       {{ py3('oslo.config')}}
Requires:       {{ py3('oslo.context') }}
Requires:       {{ py3('oslo.db') }}
Requires:       {{ py3('oslo.i18n') }}
Requires:       {{ py3('oslo.log') }}
Requires:       {{ py3('oslo.messaging') }}
Requires:       {{ py3('oslo.policy') }}
Requires:       {{ py3('oslo.service')}}
Requires:       {{ py3('oslo.utils') }}
Requires:       {{ py3('oslo.versionedobjects') }}
Requires:       {{ py3('pbr') }}
Requires:       {{ py3('pecan') }}
Requires:       {{ py3('psutil') }}
Requires:       {{ py3('six') }}
Requires:       {{ py3('stevedore') }}

%description -n python3-{{ pypi_name }}
Cyborg (previously known as Nomad) is an OpenStack project that aims to
provide a general purpose management framework for acceleration
resources (i.e. various types of accelerators such as GPU, FPGA, ASIC,
NP, SoCs, NVMe/NOF SSDs, ODP, DPDK/SPDK and so on).

This package contains the Cyborg python libraries.

%package doc
Summary:        Documentation for OpenStack Backup Service
Group:          Documentation/HTML
BuildRequires:  fdupes
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('os-api-ref') }}
BuildRequires:  {{ py3('sphinx-feature-classification') }}
BuildRequires:  {{ py3('sphinxcontrib-pecanwsme') }}
BuildRequires:  {{ py3('sphinxcontrib-seqdiag') }}
BuildRequires:  {{ py3('sphinxcontrib-svg2pdfconverter') }}

%description doc
OpenStack Cyborg documentation.

This package contains the documentation

%prep
%autosetup -p1 -n openstack-{{ pypi_name }}-{{upstream_version}}
%py_req_cleanup

%build
%{py3_build}

PBR_VERSION={{ upstream_version }} %sphinx_build -b html doc/source doc/build/html
PBR_VERSION={{ upstream_version }} %sphinx_build -b man doc/source doc/build/man
rm -r doc/build/html/.{doctrees,buildinfo}

# config file generation
PYTHONPATH=. oslo-config-generator --config-file tools/config/cyborg-config-generator.conf \
    --output-file etc/cyborg/cyborg.conf.sample
PYTHONPATH=. oslopolicy-sample-generator --config-file tools/config/cyborg-policy-generator.conf \
    --output-file etc/cyborg/policy.json.sample

%install
%{py3_install}
install -d -m 755 %{buildroot}%{_localstatedir}/log/cyborg
install -d -m 755 %{buildroot}%{_sysconfdir}/cyborg

mv %{buildroot}%{_prefix}%{_sysconfdir}/cyborg/*  %{buildroot}%{_sysconfdir}/cyborg/
install -p -D -m 640 etc/cyborg/cyborg.conf.sample %{buildroot}%{_sysconfdir}/cyborg/cyborg.conf
install -p -D -m 640 etc/cyborg/policy.json.sample %{buildroot}%{_sysconfdir}/cyborg/policy.json

# remove duplicates
%fdupes %{buildroot}%{python3_sitelib}

%pre
%openstack_pre_user_group_create cyborg cyborg /sbin/nologin

%files
%license LICENSE
%doc README.rst
%{_bindir}/cyborg-api
%{_bindir}/cyborg-conductor
%{_bindir}/cyborg-dbsync
%{_bindir}/cyborg-agent
%{_bindir}/cyborg-status
%{_bindir}/{{pypi_name}}-wsgi-api
%dir %attr(0750, root, cyborg) %{_sysconfdir}/cyborg/
%config(noreplace) %attr(0640, root, cyborg) %{_sysconfdir}/cyborg/cyborg.conf
%config(noreplace) %attr(0640, root, cyborg) %{_sysconfdir}/cyborg/api-paste.ini
%config(noreplace) %attr(0640, root, cyborg) %{_sysconfdir}/cyborg/policy.json
%config(noreplace) %attr(0640, root, cyborg) %{_sysconfdir}/cyborg/policy.yaml
%dir %attr(0750, cyborg, cyborg) %{_localstatedir}/log/cyborg

%files -n python3-{{ pypi_name }}
%doc README.rst
%license LICENSE
%{python3_sitelib}/cyborg/
%{python3_sitelib}/openstack_cyborg*.egg-info

%files doc
%license LICENSE
%doc doc/build/html

%changelog
